import jaydebeapi
from .basic import DatabaseUtil


class DaMengUtil(DatabaseUtil):

    def __init__(self,user,password,ip,port=5236,**kwargs):
        self.CURSOR = {}
        if 'database' not in kwargs:
            database=user
        else:
            database=kwargs['database']
        # if 'login_mode' not in kwargs:
        #     login_mode=1
        # else:
        #     login_mode=kwargs['login_mode']
        jclassname = 'dm.jdbc.driver.DmDriver'
        url=f"jdbc:dm://{database}?{database}=({ip}:{port})"
        driver_args=[user,password]
        jarFile=self.getJarFile()
        self.db=jaydebeapi.connect(jclassname,url,driver_args,jarFile)
        self.db.jconn.setAutoCommit(False)


if __name__ == '__main__':
    with DaMengUtil('SYSDBA','SYSDBA','10.20.249.125') as db:
        # db.execsql("select count(*) as COUNT from hsinfo.\"__info_h_bondprice_TEMP\"")
        r=db.execsql("select * from hsinfo.info_h_bondprice")
        #logger.info(r)
